package com.android.boncen.commonFrame.fragment;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;

import com.android.boncen.commonFrame.R;
import com.android.boncen.commonFrame.base.BaseFragment;
import com.android.boncen.commonFrame.fragment.recommend_framents.recommend_eat_fragment;
import com.android.boncen.commonFrame.fragment.recommend_framents.recommend_sport_fragment;

import java.util.ArrayList;
import java.util.List;

public class recommendFragment extends BaseFragment {

    private View rootView;
    private TabLayout recommend_tablayout;
    private ViewPager viewPager;

    private TextView titleBar_title;

    private List<Fragment> fragments = new ArrayList<>();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }


    @Override
    protected View initView() {
        if (rootView == null) {
            rootView = View.inflate(mContext, R.layout.recommend_fragment, null);
        }
        titleBar_title = (TextView) rootView.findViewById(R.id.tv_title);
        recommend_tablayout = (TabLayout) rootView.findViewById(R.id.recommend_tablayout);
        viewPager = (ViewPager) rootView.findViewById(R.id.recommend_viewpager);
        fragments.add(new recommend_eat_fragment(mContext,"饮食推荐"));
        fragments.add(new recommend_sport_fragment(mContext,"运动推荐"));
        return rootView;
    }


    @Override
    protected void initData() {
        super.initData();
        titleBar_title.setText("推荐");
        viewPager.setAdapter(new myViewPagerAdapter(getFragmentManager()));
        recommend_tablayout.setupWithViewPager(viewPager);
    }

    class myViewPagerAdapter extends FragmentPagerAdapter {


        public myViewPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return fragments.get(position);
        }

        @Override
        public int getCount() {
            return fragments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
           if(position==0){
               return "饮食推荐";
           }else if (position==1){
               return "运动推荐";
           }
            return "推荐";
        }
    }
}
